<?php

namespace Biz\model\IkeaActivity;

use Doraemon\pockets\datebase\BaseDbModel;

class IkeaActivityWinnerListModel extends BaseDbModel
{

    public const _CONFIG_FILE_ = 'db_store';


    public const _CONFIG_SELECT_ = 'db_brand_activity';

    public const _DATABASE_ = 'brand_activity';


    public const _TABLE_NAME = 'ikea_activity_winner_list';


    const STATUS_NORMAL = 1;
    const STATUS_DELETE = 9;

    public static function insertData($data)
    {
        if (!isset($data['addtime'])) {
            $data['addtime'] = date('Y-m-d H:i:s');
        }
        if (!isset($data['edittime'])) {
            $data['edittime'] = date('Y-m-d H:i:s');
        }
        $ret = self::insert($data);
        if ($ret->errorCode() !== '00000') {
            return false;
        }

        return self::id();
    }

    public static function updateDataByWhere($data, $where): bool
    {
        if (!isset($data['edittime'])) {
            $data['edittime'] = date('Y-m-d H:i:s');
        }
        $ret = self::update($data, $where);
        if ($ret->errorCode() !== '00000') {
            return false;
        }

        return true;
    }

    public static function selectByWhere($where, $field = '*'): array
    {
        return self::select($field, $where) ?? [];
    }


    public static function getByWhere($where, $field = '*')
    {
        return self::get($field, $where) ?? [];
    }

}